package LexPortal.Servlets;

import javax.servlet.*;
import javax.servlet.http.*;
import LexPortal.Entity.*;
import LexPortal.DaoImpl.*;

public class RegisterServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8568093138835162511L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) {

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) {
		try {
			// request.setCharacterEncoding("UTF-8");
			User newUser = new User();

			String userName = request.getParameter("username");
			String password = request.getParameter("password");
			String cfmpassword = request.getParameter("confirm_password");
			String address = request.getParameter("address");
			String email = request.getParameter("email");
			String phone = request.getParameter("phone");
			
			if (password.endsWith(cfmpassword)) {
				
				newUser.setName(userName);
				newUser.setPassword(password);
				newUser.setAddress(address);
				newUser.setEmail(email);
				newUser.setPhone(phone);

				UserDaoImpl userDao = new UserDaoImpl();
				userDao.Insert(newUser);

				RequestDispatcher dispatcher = request
						.getRequestDispatcher("Test.jsp");
				dispatcher.forward(request, response);
			} else {
				RequestDispatcher dispatcher = request
						.getRequestDispatcher("Registration.jsp");
				dispatcher.forward(request, response);
			}

		} catch (Exception ex) {

		}
	}
}
